package smartlifev30.com.sdk.api.gateway_app;

import android.support.annotation.NonNull;

import smartlifev30.com.sdk.util.JsonUtil;
import smartlifev30.com.sdk.api.CallBack;
import smartlifev30.com.sdk.api.ConstantGateway;
import smartlifev30.com.sdk.bean.request.SetGatewaySnRequest;
import smartlifev30.com.sdk.bean.request.SetGwAliasRequest;
import smartlifev30.com.sdk.bean.request.SetNetworkParamsRequest;
import smartlifev30.com.sdk.bean.request.ZbNetOpenRequest;
import smartlifev30.com.sdk.net.baiwei.NetManager;

/**
 * 网关管理模块
 *
 * @author tys
 * @date 2018/8/15
 */

public class GatewayMgmtImpl implements IGatewayMgmt {


    @Override
    public void setGatewaySn(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull String oldSn, @NonNull String newSn, @NonNull CallBack<String> callBack) {
        SetGatewaySnRequest setGatewaySnRequest = new SetGatewaySnRequest();
        setGatewaySnRequest.setFrom(userName);
        setGatewaySnRequest.setTo(sn);
        setGatewaySnRequest.setMsg_id(callBack.getMsgId());
        setGatewaySnRequest.setMsg_class(ConstantGateway.MSG_CLASS_GATEWAY);
        setGatewaySnRequest.setMsg_name("sn_set");
        setGatewaySnRequest.setMsg_type(ConstantGateway.MSG_TYPE_SET);
        setGatewaySnRequest.setToken(token);
        setGatewaySnRequest.setGateway(setGatewaySnRequest.new Gateway(oldSn, newSn));
        NetManager.getInstance().sendMessage(JsonUtil.toString(setGatewaySnRequest));
    }

    @Override
    public void setNetworkParams(@NonNull String userName, @NonNull String token, @NonNull String sn,
                                 @NonNull SetNetworkParamsRequest.Gateway gateway, @NonNull CallBack<String> callBack) {
        SetNetworkParamsRequest setNetworkParamsRequest = new SetNetworkParamsRequest();
        setNetworkParamsRequest.setFrom(userName);
        setNetworkParamsRequest.setTo(sn);
        setNetworkParamsRequest.setMsg_id(callBack.getMsgId());
        setNetworkParamsRequest.setMsg_class(ConstantGateway.MSG_CLASS_GATEWAY);
        setNetworkParamsRequest.setMsg_name("network_set");
        setNetworkParamsRequest.setMsg_type(ConstantGateway.MSG_TYPE_SET);
        setNetworkParamsRequest.setToken(token);
        setNetworkParamsRequest.setGateway(gateway);
        NetManager.getInstance().sendMessage(JsonUtil.toString(setNetworkParamsRequest));
    }

    @Override
    public void zbNetOpen(@NonNull String userName, @NonNull String token, @NonNull String sn,
                          @NonNull Integer time, @NonNull CallBack<String> callBack) {
        ZbNetOpenRequest zbNetOpenRequest = new ZbNetOpenRequest();
        zbNetOpenRequest.setFrom(userName);
        zbNetOpenRequest.setTo(sn);
        zbNetOpenRequest.setMsg_id(callBack.getMsgId());
        zbNetOpenRequest.setMsg_class(ConstantGateway.MSG_CLASS_GATEWAY);
        zbNetOpenRequest.setMsg_name("zb_net_open");
        zbNetOpenRequest.setMsg_type(ConstantGateway.MSG_TYPE_SET);
        zbNetOpenRequest.setToken(token);
        zbNetOpenRequest.setTime(time);
        NetManager.getInstance().sendMessage(JsonUtil.toString(zbNetOpenRequest));
    }

    @Override
    public void setGwAlias(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull String alias, @NonNull CallBack<String> callBack) {
        SetGwAliasRequest setGwAliasRequest = new SetGwAliasRequest();
        setGwAliasRequest.setFrom(userName);
        setGwAliasRequest.setTo(sn);
        setGwAliasRequest.setMsg_id(callBack.getMsgId());
        setGwAliasRequest.setMsg_class(ConstantGateway.MSG_CLASS_GATEWAY);
        setGwAliasRequest.setMsg_name("gw_alias_set");
        setGwAliasRequest.setMsg_type(ConstantGateway.MSG_TYPE_SET);
        setGwAliasRequest.setToken(token);
        setGwAliasRequest.setGateway(setGwAliasRequest.new Gateway(alias));
        NetManager.getInstance().sendMessage(JsonUtil.toString(setGwAliasRequest));
    }




}
